home *** CD-ROM | disk | FTP | other *** search
- #include <stddef.h>
- #include <osbind.h>
- #include <mintbind.h>
- #include <string.h>
- #include "global.h"
- #include "pipe.h"
-
-
- /* error messages, cribbed directly out of STIK.ACC */
- char *errors[] = {
- "No error",
- "Output Buffer full",
- "No data available",
- "EOF from remote",
- "RST received from remote",
- "RST. Other end sent unacceptable pkt",
- "No memory available",
- "Connection refused by remote",
- "A SYN was received in the window",
- "Bad connection handle used",
- "Socket in LISTEN state, can't send",
- "No free CCB's available",
- "No connection matches this packet (TCP)",
- "Failure to connect to remote port (TCP)",
- "Invalid TCP_close() requested",
- "User timout expired",
- "Connection timed out",
- "Domain query, Can't resolve",
- "Bad format in domain name or dotted decimal",
- "Modem is not connected",
- "Hostname does not exist",
- "Resolver reached work limit",
- "No nameserver found",
- "Bad format of DNS query",
- "Destination unreachable",
- "No Address records found for name"
- };
- char error_error[] = "Unrecognized error code";
-
- Daemon_Op OP_;
- Daemon_Retval RET_;
-
-
- int init_stubs()
- {
- return 1;
- }
-
-
- void send_op(Daemon_Op *op, Daemon_Retval *ret)
- {
- PMSG pmsg;
-
- #ifdef DEBUG
- debug("s", "Grabbing daemon semaphore");
- #endif
- Psemaphore(2, DMN_SEMAPHORE, -1L);
- OP_ = *op;
- pmsg.userlong1 = (long)&OP_;
- pmsg.userlong2 = (long)&RET_;
- #ifdef DEBUG
- debug("sd", "Sending op ", OP_.common.op);
- #endif
- Pmsg(2, DMN_MBOX, &pmsg);
- #ifdef DEBUG
- debug("sd", "Returned from op ", OP_.common.op);
- #endif
- *ret = RET_;
- Psemaphore(3, DMN_SEMAPHORE, 0L);
- #ifdef DEBUG
- debug("s", "Releasing daemon semaphore");
- #endif
- }
-
-
- char* do_get_err_text(int16 err)
- {
- char *s;
-
- #ifdef DEBUG
- debug("s", "in get_err_text()");
- #endif
- /* GlueSTiK extension: for MiNTnet errno values that don't neatly
- correspond to STiK error codes, we return (-1000 - errno) and
- translate it back here. */
- if (err < 0)
- err = -err;
- if (err > 1000 && (s = strerror(err - 1000)))
- return s;
- if (err > E_LASTERROR)
- return error_error;
- return errors[err];
- }
-
- /* Incompatibility: Does nothing. We can't really support this well,
- since MiNTnet transparently supports multiple modems, as well as
- non-modem methods of connections, such as local networks */
- int16 do_carrier_detect(void)
- {
- #ifdef DEBUG
- debug("s", "in carrier_detect()");
- #endif
- return 0;
- }
-
- int16 do_TCP_open(uint32 hostaddr, int16 port, int16 tos, uint16 obsize)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_TCP_open.op = OP_TCP_OPEN;
- OP.P_TCP_open.hostaddr = hostaddr;
- OP.P_TCP_open.port = port;
- OP.P_TCP_open.tos = tos;
- OP.P_TCP_open.obsize = obsize;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- int16 do_TCP_close(int16 fd, int16 timeout)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_TCP_close.op = OP_TCP_CLOSE;
- OP.P_TCP_close.fd = fd;
- OP.P_TCP_close.timeout = timeout;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- int16 do_TCP_send(int16 fd, char* buf, int16 buflen)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_TCP_send.op = OP_TCP_SEND;
- OP.P_TCP_send.fd = fd;
- OP.P_TCP_send.buf = buf;
- OP.P_TCP_send.buflen = buflen;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- int16 do_TCP_wait_state(int16 fd, int16 state, int16 timeout)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_TCP_wait_state.op = OP_TCP_WAIT_STATE;
- OP.P_TCP_wait_state.fd = fd;
- OP.P_TCP_wait_state.state = state;
- OP.P_TCP_wait_state.timeout = timeout;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- /* Incompatibility: Does nothing. MiNTnet handles this internally. */
- int16 do_TCP_ack_wait(int16 fd, int16 timeout)
- {
- #ifdef DEBUG
- debug("s", "in TCP_ack_wait()");
- #endif
- return E_NORMAL;
- }
-
- int16 do_UDP_open(uint32 hostaddr, int16 port)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_UDP_open.op = OP_UDP_OPEN;
- OP.P_UDP_open.hostaddr = hostaddr;
- OP.P_UDP_open.port = port;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- int16 do_UDP_close(int16 fd)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_UDP_close.op = OP_UDP_CLOSE;
- OP.P_UDP_close.fd = fd;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- int16 do_UDP_send(int16 fd, char* buf, int16 buflen)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_UDP_send.op = OP_UDP_SEND;
- OP.P_UDP_send.fd = fd;
- OP.P_UDP_send.buf = buf;
- OP.P_UDP_send.buflen = buflen;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- /* Incompatibility: Does nothing. MiNTnet handles its own "kicking" */
- int16 do_CNkick(int16 fd)
- {
- #ifdef DEBUG
- debug("s", "in CNkick()");
- #endif
- return E_NORMAL;
- }
-
- int16 do_CNbyte_count(int16 fd)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_CNbyte_count.op = OP_CNBYTE_COUNT;
- OP.P_CNbyte_count.fd = fd;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- int16 do_CNget_char(int16 fd)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_CNget_char.op = OP_CNGET_CHAR;
- OP.P_CNget_char.fd = fd;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- NDB* do_CNget_NDB(int16 fd)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_CNget_NDB.op = OP_CNGET_NDB;
- OP.P_CNget_NDB.fd = fd;
- send_op(&OP, &RET);
- return RET.ret_NDBptr;
- }
-
- int16 do_CNget_block(int16 fd, char* buf, int16 len)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_CNget_block.op = OP_CNGET_BLOCK;
- OP.P_CNget_block.fd = fd;
- OP.P_CNget_block.buf = buf;
- OP.P_CNget_block.len = len;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- void do_housekeep(void)
- {
- /* do nothing */
- }
-
- int16 do_resolve(char *hostname, char **realname, uint32 *addrs, int16 naddrs)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_resolve.op = OP_RESOLVE;
- OP.P_resolve.hostname = hostname;
- OP.P_resolve.realname = realname;
- OP.P_resolve.addrs = addrs;
- OP.P_resolve.naddrs = naddrs;
- send_op(&OP, &RET);
- return RET.ret_int16;
- }
-
- void do_ser_disable(void)
- {
- /* do nothing */
- }
-
- void do_ser_enable(void)
- {
- /* do nothing */
- }
-
- CIB* do_CNgetinfo(int16 fd)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_CNgetinfo.op = OP_CNGETINFO;
- OP.P_CNgetinfo.fd = fd;
- send_op(&OP, &RET);
- return RET.ret_CIBptr;
- }
-
- char* do_KRmalloc(int32 size)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_KRmalloc.op = OP_KRMALLOC;
- OP.P_KRmalloc.size = size;
- send_op(&OP, &RET);
- return RET.ret_charptr;
- }
-
- void do_KRfree(void *mem)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_KRfree.op = OP_KRFREE;
- OP.P_KRfree.mem = mem;
- send_op(&OP, &RET);
- }
-
- int32 do_KRgetfree(int16 flag)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_KRgetfree.op = OP_KRGETFREE;
- OP.P_KRgetfree.flag = flag;
- send_op(&OP, &RET);
- return RET.ret_int32;
- }
-
- char* do_KRrealloc(char *mem, int32 newsize)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_KRrealloc.op = OP_KRREALLOC;
- OP.P_KRrealloc.mem = mem;
- OP.P_KRrealloc.newsize = newsize;
- send_op(&OP, &RET);
- return RET.ret_charptr;
- }
-
-
- char *do_getvstr(char *var)
- {
- Daemon_Op OP;
- Daemon_Retval RET;
-
- OP.P_getvstr.op = OP_GETVSTR;
- OP.P_getvstr.var = var;
- send_op(&OP, &RET);
- return RET.ret_charptr;
- }
-